var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
import React, { useRef } from "react";
import PickerPanel from "../components/picker-panel";
import DatePicker from "../components/date-picker";
import useOverlay from "./useOverlay";
// !!!: 一定要在页面上添加{overlay.overlayView}
var useDatePicker = function () {
    var overlay = useOverlay();
    var dateValueRef = useRef();
    var show = function (props) {
        return overlay.show(function () {
            return (React.createElement(PickerPanel, __assign({}, props, { title: props.title, onConfirm: function () {
                    overlay.close();
                    props.onConfirm &&
                        dateValueRef.current &&
                        props.onConfirm(dateValueRef.current);
                    dateValueRef.current = undefined;
                }, onCancel: function () {
                    overlay.close();
                    props.onCancel && props.onCancel();
                } }),
                React.createElement(DatePicker, __assign({}, props, { onChange: function (value) {
                        dateValueRef.current = value;
                    } }))));
        }, {
            type: "slid-up"
        });
    };
    return __assign(__assign({}, overlay), { show: show });
};
export default useDatePicker;
